package net.neimeng.luculent.address;

import android.arch.lifecycle.ViewModelProviders;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.alibaba.android.arouter.facade.annotation.Route;

import net.neimeng.luculent.address.databinding.AddressFragmentTabBinding;
import net.neimeng.luculent.commonmodule.entities.Contacts;
import net.neimeng.luculent.commonmodule.router.AddressRouterPath;
import net.neimeng.luculent.commonmodule.viewmodel.AddressTabViewModel;
import net.neimeng.luculent.coremodel.base.lifecycle.LCObserver;
import net.neimeng.luculent.coremodel.base.view.BaseFragment;
import net.neimeng.luculent.coremodel.datamodel.http.ListResult;

@Route(path = AddressRouterPath.ADDRESS_TAB)
public class AddressTabFragment extends BaseFragment {

    private AddressFragmentTabBinding binding;

    private AddressTabViewModel viewModel;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        onInit();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.address_fragment_tab, container, false);

        return binding.getRoot();
    }

    public void onInit(){
        viewModel = ViewModelProviders.of(this).get(AddressTabViewModel.class);
        onObserve();
    }

    private void onObserve(){
        viewModel.getContacts().observe(this, new LCObserver<ListResult<Contacts>>() {
            @Override
            public void onSuccess(ListResult<Contacts> contactsListResult) {

            }
        });
    }

}
